﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace Royaumes_Libres.Database
{

    /// <summary>
    /// Peuple les combo box
    /// </summary>
    /// <remarks>Maxime Dubois</remarks>
    public class cCboPop
    {
        /// <summary>
        /// Maxime Dubois
        /// </summary>
        public cCboPop()
        {
        }

        /// <summary>
        /// va chercher toute les langues
        /// </summary>
        /// <returns>retourne un array contenant les langues</returns>
        /// <remarks>Maxime Dubois</remarks>
        public static Array GetArrayLangs()
        {
            Dictionary<string, string> pDictionnaire;
            pDictionnaire = new Dictionary<string, string>();

            SqlCommand cmd = cSQL.GetDbSiteCommand();
            cmd.Connection.Open();
            cmd.CommandText = "cde.spGetLangues";
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                pDictionnaire.Add(dr.GetString(0), dr.GetString(1));
            }

            cmd.Connection.Close();
            
            return pDictionnaire.ToArray();
        }

        /// <summary>
        /// va chercher toute les pays
        /// </summary>
        /// <returns>retourne un array contenant les pays</returns>
        /// <remarks>Maxime Dubois</remarks>
        public static Array GetArrayCountries()
        {
            Dictionary<string, string> pDictionnaire;
            pDictionnaire = new Dictionary<string, string>();

            SqlCommand cmd = cSQL.GetDbSiteCommand();
            cmd.Connection.Open();
            cmd.CommandText = "spGetCountries";
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                pDictionnaire.Add(Convert.ToString(dr.GetInt32(0)), dr.GetString(1));
            }

            cmd.Connection.Close();

            return pDictionnaire.ToArray();
        }

        /// <summary>
        /// va chercher toute les etats/provinces
        /// </summary>
        /// <returns>retourne un array contenant les etats/provinces</returns>
        /// <remarks>Maxime Dubois</remarks>
        public static Array GetArrayStates(int FkCountry)
        {
            Dictionary<string, string> pDictionnaire;
            pDictionnaire = new Dictionary<string, string>();

            SqlCommand cmd = cSQL.GetDbSiteCommand();
            cmd.Connection.Open();
            cmd.CommandText = "spGetStates";
            cmd.Parameters.Add(cSQL.Param("@FkCountry", FkCountry, SqlDbType.Int));
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                pDictionnaire.Add(Convert.ToString(dr.GetInt32(0)), dr.GetString(1));
            }

            cmd.Connection.Close();

            return pDictionnaire.ToArray();
        }

        /// <summary>
        /// va chercher toute les villes
        /// </summary>
        /// <returns>retourne un array contenant les villes</returns>
        /// <remarks>Maxime Dubois</remarks>
        public static Array GetArrayCities(int FkState)
        {
            Dictionary<string, string> pDictionnaire;
            pDictionnaire = new Dictionary<string, string>();

            SqlCommand cmd = cSQL.GetDbSiteCommand();
            cmd.Connection.Open();
            cmd.CommandText = "spGetCities";
            cmd.Parameters.Add(cSQL.Param("@FkState", FkState, SqlDbType.Int));
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                pDictionnaire.Add(Convert.ToString(dr.GetInt32(0)), dr.GetString(1));
            }

            cmd.Connection.Close();

            return pDictionnaire.ToArray();
        }
    }
}